package com.example.geomanager;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class PinpointItemizedOverlay extends ItemizedOverlay<OverlayItem> {
	
	private ArrayList<OverlayItem> pinpoints = new ArrayList<OverlayItem>();
	private Context context;

	public PinpointItemizedOverlay(Drawable defaultMarker, Context context) {
		super(boundCenterBottom(defaultMarker));
		this.context = context;
	}

	@Override
	protected OverlayItem createItem(int index) {
		return pinpoints.get(index);
	}

	@Override
	public int size() {
		return pinpoints.size();
	}
	
	@Override
	protected boolean onTap(int index)
	{
		OverlayItem item = pinpoints.get(index);
		
		AlertDialog.Builder dialog = new AlertDialog.Builder(context);
		dialog.setTitle(item.getTitle());
		dialog.setMessage(item.getSnippet());
		dialog.show();
		
		return true;
	}

	public void addOverlay(OverlayItem overlay)
	{
		pinpoints.add(overlay);
		populate();
	}
}
